﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;

namespace Planer.Model
{
    public enum ActionType { INCOME, OUTCOME};

    public class ActionModel
    {
        static ActionModel model = null;

        protected ActionModel()
        {            
        }

        public static ActionModel GetInstance()
        {
            if (model == null)
            {
                model = new ActionModel();
            }

            return model;
        }

        public ModelResult AddAction(action Action)
        {
            Program.Db.AddToactions(Action);
            int res = Program.Db.SaveChanges();
           
            if(! (res > 0))
                return new ModelResult("Ошибка сохранения действия");
            return new ModelResult();
            
            //return new ModelResult("Ошибка сохранения действия");
        }

        public List<action> GetActionsByBilling(billing Bill)
        {
            period p = PeriodModel.GetInstance().GetCurrentPeriod();

            var query = from act in Program.Db.actions.Include("action_category").Include("billing")
                        where act.billing.id == Bill.id && act.period.id == p.id
                        orderby act.create_date descending
                        select act;

            return new List<action>(query.ToArray<action>());
        }        
        
    }
}
